package com.fare.taluo.web.action;

import java.io.IOException;
import java.util.ArrayList;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fare.taluo.BaseFdcAction;
import com.fare.taluo.application.EarningsExportApplication;
import com.fare.taluo.auth.security.LogonUserCertificate;
import com.fare.taluo.ftp.FtpConfigurationManager;
import com.fare.taluo.vo.core.report.EarningsExportVO;

@Namespace("/")
@Controller("earningsReportAction")
@Scope("prototype")
public class EarningsReportAction extends BaseFdcAction{
	
	private String returnPageURL;
	

	@Resource(name="earningsExportApplicationImpl")
	private EarningsExportApplication earningsExportApp;
	//输入
	private Long[] ids;
	private String filepath;
	private String time;
	private boolean enabled;
	private Integer grapDelayTime  =10;
	//输出
	private ArrayList<String> hostlist;//保存一个端口的ip list
	private EarningsExportVO earnVo;

	
	//保存数据
	public void save() throws IOException {
		earnVo = new EarningsExportVO();
		String returnValue = "";
		try{
			LogonUserCertificate user = com.fare.taluo.auth.security.ContextLoginUser.getLoginUser();
			earnVo.setHostid(filepath);
			earnVo.setIds(ids);
			earnVo.setTimeDesc(time);
			earnVo.setEnabled(enabled);
			earnVo.setCreator(user.getLocalUserId());
			earnVo.setCreatorName(user.getUserName());
			earnVo.setGrapDelayTime(grapDelayTime);
			earningsExportApp.save(earnVo);
			returnValue = "ok";
		}catch(Exception e){
			e.printStackTrace();
			returnValue = e.getMessage();
		}finally{
			ServletActionContext.getResponse().getWriter().print(returnValue);
		}
	}
	
	//需要显示路径和时间点
	public String show() throws Exception{
		returnPageURL="/fare/_sybbdc.jsp";	
		earnVo = earningsExportApp.find();
		//设置启用的标签
		ArrayList<String> lst=new ArrayList<String>(FtpConfigurationManager
				.getInstance().getFtpConfigurations().keySet());
		hostlist=new ArrayList<String>();
		for(int i=0;i<lst.size();i++){
			String str="ftp://"+lst.get(i);
			hostlist.add(str);
		}
		return "dispatcher";
	}



	public Long[] getIds() {
		return ids;
	}

	public void setIds(Long[] ids) {
		this.ids = ids;
	}

	public String getReturnPageURL() {
		return returnPageURL;
	}

	public void setReturnPageURL(String returnPageURL) {
		this.returnPageURL = returnPageURL;
	}

	public String getFilepath() {
		return filepath;
	}

	public void setFilepath(String filepath) {
		this.filepath = filepath;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public ArrayList<String> getHostlist() {
		return hostlist;
	}

	public void setHostlist(ArrayList<String> hostlist) {
		this.hostlist = hostlist;
	}

	public EarningsExportVO getEarnVo() {
		return earnVo;
	}

	public void setEarnVo(EarningsExportVO earnVo) {
		this.earnVo = earnVo;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public Integer getGrapDelayTime() {
		return grapDelayTime;
	}

	public void setGrapDelayTime(Integer grapDelayTime) {
		this.grapDelayTime = grapDelayTime;
	}
	
	
}
